package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class BorrowOperation implements Ioperateion {
    @Override
    public void work(BookList books) {
        System.out.println("借阅图书!");
        System.out.println("请输入借阅图书的名字");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();

        int currentSize = books.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            Book book = books.getBook(i);
            if (book.getName().equals(name)) {
                if (book.isBorrowed() == true) {
                    System.out.println("该书已经被借出");
                } else {
                    book.setBorrowed(true);
                    System.out.println("借阅成功");
                }
            }
        }
        System.out.println("没有你要借阅的这本书");
    }
}
